import axios from 'axios';

export const loginAction = isLogin => {
    return dispatch => {
        const action = {
            type: 'LOGIN',
            isLogin,
        };
        dispatch(action);
    };
};

export const login = (account, password) => {
    return dispatch => {
        let data = {
            user: account,
            password: password,
        };
        axios
            .post('https://www.fastmock.site/mock/0764b93cba70add273910b232c51aad8/development/api/login', data)
            .then(res => {
                let data = res.data.data;
                if (data.success) {
                    const action = loginAction(true);
                    dispatch(action);
                } else {
                    alert(data.msg);
                }
            })
            .catch(error => {
                console.log(error);
            });
    };
};
